package com.edaoe.module.api;

import com.edaoe.module.api.admin.ApiAdminService;
import com.jfinal.core.Controller;

/**
 * Created by Dull on 2017/6/3 0003.
 */
public class ApiController extends Controller {
    private ApiService srv=new ApiService();
    private static final int PAGE_SIZE=10;

    /**
     * 用户导航菜单
     */
    public void navs(){
        String nickname=getPara("nickname");
        renderJson(srv.navs(nickname));
    }

    public void index(){
        int pageNumber=getParaToInt("pageNumber");
        renderJson(srv.index(pageNumber,PAGE_SIZE));
    }

    public void search(){
        String searchText=getPara("searchText");
        int pageNumber=getParaToInt("pageNumber");
        renderJson(srv.search(searchText,pageNumber,PAGE_SIZE));
    }

    public void userIndex(){
        String nickname=getPara("nickname");
        int pageNumber=getParaToInt("pageNumber");
        renderJson(srv.userIndex(nickname,pageNumber,PAGE_SIZE));
    }

    public void userSearch(){
        String nickname=getPara("nickname");
        String searchText=getPara("searchText");
        int pageNumber=getParaToInt("pageNumber");
        renderJson(srv.userSearch(nickname,searchText,pageNumber,PAGE_SIZE));
    }

    public void userCategory(){
        String nickname=getPara("nickname");
        String categoryName=getPara("categoryName");
        int pageNumber=getParaToInt("pageNumber");
        renderJson(srv.userCategory(nickname,categoryName,pageNumber,PAGE_SIZE));
    }

    public void userTag(){
        String nickname=getPara("nickname");
        String tagName=getPara("tagName");
        int pageNumber=getParaToInt("pageNumber");
        renderJson(srv.userTag(nickname,tagName,pageNumber,PAGE_SIZE));
    }

    public void article(){
        long articleId=getParaToLong("articleId");
        renderJson(srv.article(articleId));
    }

    public void rebuild(){
        new ApiAdminService().rebuildIndex();
        renderText("ok");
    }

    public void tag(){
        String nickname=getPara("nickname");
        renderJson(srv.tag(nickname));
    }

}
